

clear *
set more off, permanently
*set your local directory, in which you have saved defaults_donations.dta
cd "[INSERT LOCAL DIRECTORY HERE]"
use defaults_donations.dta

log using "tables+tests.log", replace

***********************************************************
***********************************************************
*
* TABLE OF CONTENTS
*
* A) Tables
*	 Tables 1 - 5
*	 Table A.1
*
* B) Tests
*	 Section 3.1: distribution tests
*	 Section 3.2: treatment differences in donation levels and donation rates
*	 Section 3.3: treatment differences in codonation levels
*
* C) Further descriptive analysis and robustness checks
*	 Section 2.3
*	 Section 3.1
*	 Section 3.2
*	 Section 3.3
*
************************************************************
************************************************************







***********************************************************
***********************************************************
*****                A) TABLES                        *****
***********************************************************
***********************************************************


***************************************
***  Table 1                        ***
***************************************

use defaults_donations.dta, clear

*drop top 0.2% of donors with highest donation levels
drop if q99_8==1

*Number of observations per treatment
tab default_donation default_codonation




***************************************
***  Table 2                        ***
***************************************

use defaults_donations.dta, clear

*drop top 0.2% of donors with highest donation levels
drop if q99_8==1

*Donation rate
tabstat donate,  s(n mean med sd)  columns(statistics) format(%10.4g)

*Donated & codonated amounts
keep if donate==1
tabstat donated_amount codonated_amount,  s(n mean med sd)  columns(statistics) format(%10.4g)





***************************************
***  Table 3                        ***
***************************************

use defaults_donations.dta, clear

*drop top 0.2% of donors with highest donation levels
drop if q99_8==1

*generate donation amount categories
gen donate_grid = .
replace donate_grid = 10 if donated_amount==10
replace donate_grid = 20 if donated_amount==20
replace donate_grid = 50 if donated_amount==50
replace donate_grid = 999 if donated_amount!=0 & donated_a!=10 & donated_a!=20 & donated_a !=50

*plot table
bys default_donation default_codonation: tab donate_grid




***************************************
***  Table 4                        ***
***************************************

use defaults_donations.dta, clear

*drop top 0.2% of donors with highest donation levels
drop if q99_8==1

gen codonate_grid=.
replace codonate_grid = 0 if codonated_pct==0
replace codonate_grid = 5 if codonated_pct==5
replace codonate_grid = 10 if codonated_pct==10
replace codonate_grid = 15 if codonated_pct==15
replace codonate_grid = 999 if codonated_pct!=0 & codonated_pct!=5  & codonated_pct!=10  & codonated_pct!=15 & donate==1

*plot table
bys default_donation default_codonation: tab codonate_grid




***************************************
***  Table 5                        ***
***************************************

use defaults_donations.dta, clear

*drop top 0.2% of donors with highest donation levels
drop if q99_8==1

*Donation rate 
tabstat donate, by(default_donation) s(mean)  columns(variables) format(%10.3g)

*Average donation (overall) 
tabstat donated_amount, by(default_donation) s(n mean)  columns(statistics) format(%10.3g)

*Average and median donation (donors only)
preserve
keep if donate==1
tabstat donated_amount, by(default_donation) s(n mean med)  columns(statistics) format(%10.4g)
restore


***************************************
***  Appendix Table A.1             ***
***************************************

use defaults_donations.dta, clear

*drop top 0.2% of donors with highest donation levels
drop if q99_8==1

*Summary stats for individual treatment cells (all participants) 
bys default_donation default_codonation: su donate donated_amount codonate codonated_amount 

*Summary stats for individual treatment cells (donors only) 
bys default_donation default_codonation: su donated_amount codonate codonated_amount if donate==1

preserve
keep if donate==1
tabstat donated_amount, by(treat) s(n mean med)  columns(statistics) format(%10.4g)
restore

* Summary stats background characteristics
bys default_donation default_codonation: tab receiver_type 
bys default_donation default_codonation: tab tax_deductible

*F-Tests
foreach x in Event Project Element{
gen `x'=1 if receiver=="`x'"
replace `x'=0 if receiver!="`x'"
}

foreach x in Event Project Element tax_deductible {
reg `x' T010 T015 T105 T1010 T1015 T205 T2010 T2015 T505 T5010 T5015
test T010 T015 T105 T1010 T1015 T205 T2010 T2015 T505 T5010 T5015
}


***************************************
***  Appendix Table A.2             ***
***************************************

* see Readme file for further information on replication code





***********************************************************
***********************************************************
*****                B) TESTS                          ****
***********************************************************
***********************************************************



***********************************************************************
***********************************************************************
**** Distribution tests (Section 3.1)
***********************************************************************
***********************************************************************

***********************************************************************
* Donation distributions by donation default
***********************************************************************

use defaults_donations.dta, clear

*drop top 0.2% of donors with highest donation levels
drop if q99_8==1

* exclude non-donors
keep if donate == 1 
 
foreach x of varlist donated_amount  {
	local counter = 0
	token "0 10 20"
	
	di "**************************************************"
	di "******  Pooled across codonation treatments ******"	
	di "**************************************************"
	
	foreach n of num 10 20 50 20 50 50 {
		if (`counter' == 3 | `counter' == 5) {
			mac shift
		}

		di "                "
		di "                "
		di "****************"
		di "***** default_donation == `1' | `n'"
		di "****************"
		
		ksmirnov `x' if default_donation==`1' | default_donation==`n', by(default_donation)

		local ++counter 
	}
	
	di "                "
	di "                "
	di "                "
	di "                "
	di "**************************************************"
	di "****   for individual codonation defaults  *******"	
	di "**************************************************"

	foreach d of num 5 10 15 {
		preserve 
		local counter = 0
		token "0 10 20"
		keep if default_codonation == `d'
		
		foreach n of num 10 20 50 20 50 50 {
			if (`counter' == 3 | `counter' == 5) {
				mac shift
			}
			di "                "
			di "                "
			di ""
			di "****************"
			di "***** default_donation==`1' | `n'"
			di "***** KEEP default_codonation == `d' only"
			di "****************"
			
			ksmirnov `x' if default_donation==`1' | default_donation==`n', by(default_donation)

			local ++counter 
		}
		restore
	}	
}



	
***********************************************************************
* Codonation distributions by codonation default
***********************************************************************

use defaults_donations.dta, clear

*drop top 0.2% of donors with highest donation levels
drop if q99_8==1

* exclude non-donors
keep if donate == 1 
 
local counter = 0 
foreach i of num 0 10 20 50 {
	preserve 
	token "10 15 15"
	
	keep if default_donation == `i'
	
	foreach n of num 5 5 10 {
		if (mod(`counter', 3) == 0) { 
			di "" 
			di "******************************* "
			di "***** default_donation == `i'"
		}
		di "***** default_codonation == `n'|`1'"
		di "******************************* "
		ksmirnov codonated_pct if default_codonation == `n'| default_codonation == `1', by(default_codon)
		
		local ++counter 
		mac shift
	}
	restore
}



***********************************************************************
***********************************************************************
**** Section 3.2
***********************************************************************
***********************************************************************


***********************************************************************
***********************************************************************
* Average treatment effects on donations 
***********************************************************************
***********************************************************************

use defaults_donations.dta, clear

*drop top 0.2% of donors with highest donation levels
drop if q99_8==1

* NOTE: T05 is reference category
global treatList T010 T015 T105 T1010 T1015 T205 T2010 T2015 T505 T5010 T5015


**********************************
**** Pairwise tests for individual treatment cells
**********************************
reg donated_amount $treatList, cluster(session_id) 

*do all pairwise post-estimation tests
global pairList // initialize the list of pairs
local seenList // initialize the list of elements already seen
local counter = 0 //count unique combinations

foreach first of varlist $treatList {
    foreach second of local seenList {
        test `second' == `first'
		local counter = `counter' + 1
    } 
    local seenList `seenList' `first'
} 


***********************************
**** Donation levels by default donation (pooled across codonation treatments)
***********************************
global don D10 D20 D50
reg donated_amount  $don, cluster(session_id )
	test D10==D20
	test D10 ==D50
	test D20==D50
	



***********************************************************************
***********************************************************************
* Treatment dfferences in donation rates 
***********************************************************************
***********************************************************************

use defaults_donations.dta, clear

*drop top 0.2% of donors with highest donation levels
drop if q99_8==1

*D50 vs. all other treatments
reg donate D50 , cluster(session_id )

*D50 vs. individual treatments with different donation defaults
reg donate D10 D20 D50 , cluster(session_id )
test D10 = D20
test D10 = D50
test D20 = D50




***********************************************************************
***********************************************************************
**** Section 3.3
***********************************************************************
***********************************************************************


***********************************************************************
***********************************************************************
* Average treatment effects on codonations 
***********************************************************************
***********************************************************************


use defaults_donations.dta, clear

*drop top 0.2% of donors with highest donation levels
drop if q99_8==1

* NOTE: T05 is reference category
global codon T010 T015 T105 T1010 T1015 T205 T2010 T2015 T505 T5010 T5015 

reg codonated_amount $codon, cluster(session_id )

*post estimation tests for treatment differences in codonation dimension (holding donation default constant)
test T015 = T010

test T1010 = T105
test T1015 = T105
test T1010 = T1015

test T2010 = T205
test T2015 = T205
test T2010 = T2015

test T5010 = T505
test T5015 = T505
test T5010 = T5015




*******************************************************************************
*******************************************************************************
*****       C) ADDITIONAL DESCRIPTIVES AND ROBUSTNESS CHECKS              *****
*******************************************************************************
*******************************************************************************


***************************************
***  Section 2.3                    ***
***************************************

use defaults_donations.dta, clear

*drop top 0.2% of donors with highest overall donation levels
	ta donation_sum if q99_8 == 1	//>=2165
	codebook session_id if q99_8 == 1 	//41 unique session ids / users
drop if q99_8==1


*Number of donors who make more than one donation
preserve
collapse (mean) num_donations, by(session_id )
tab num_donations if num_donations > 0
restore

*Frequency of observations by donation "type" (project, element, fundraising event)
tab receiver_type

*Donation rate by donation "type" (project, element, fundraising event)
bys receiver_type: su donate

*Total amount donated / codonated during the experiment
egen overalldonation = sum(donated_amount)
egen overallcodonation = sum(codonated_amount)
su overalldonation overallcodonation



***************************************
***  Section 3.1                    ***
***************************************

***********************************************************************
* Donation distributions by CODONATION default
***********************************************************************

use defaults_donations.dta, clear

*drop top 0.2% of donors with highest donation levels
drop if q99_8==1

* exclude non-donors
keep if donate == 1 
 
local counter = 0 
foreach x of varlist donated_amount  {
	foreach i of num 0 10 20 50 {
		token "10 10 15"
		foreach n of num 5 15 5 {
			if (mod(`counter', 3) == 0) { 
				di ""
				di "****************"
				di "***** `x' "
				di "***** DONATION DEFAULT == `i'"
				di "****************"
			}
			
			di ""
			di "****************"
			di "***** `x' "
			di "***** T`i'`n'==1|T`i'`1'==1 "
			di "****************"
			
			ksmirnov `x' if T`i'`n' == 1 | T`i'`1' == 1, by(default_codon)
			
			local ++counter 
			mac shift
		}
	}
}


***********************************************************************
* Codonation distributions by DONATION default (footnote 10)
***********************************************************************

use defaults_donations.dta, clear

*drop top 0.2% of donors with highest donation levels
drop if q99_8==1

* exclude non-donors
keep if donate == 1 
 

foreach x of varlist codonated_pct  {

	foreach d of num 5 10 15 {
		preserve 
		local counter = 0
		token "0 10 20"
		
		keep if default_codonation == `d'
		
		foreach n of num 10 20 50 20 50 50 {
			if (`counter' == 3 | `counter' == 5) {
				mac shift
			}
			
			di ""
			di "****************"
			di "***** default_donation == `1' | `n'"
			di "***** KEEP default_codonation == `d' only"
			di "****************"

			
			ksmirnov `x' if default_donation==`1' | default_donation==`n', by(default_donation)

			local ++counter 
		}
		restore
	}
}




***********************************************************************
* Default adherence across both treatment dimensions
***********************************************************************

clear 
use defaults_donations.dta

*drop top 0.2% of donors with highest donation levels
drop if q99_8==1

bys codon_followdefault: tab don_followdefault if donate & default_donation >0
reg don_followdefault codon_followdefault if donate & default_donation >0, cluster(sess)



***************************************
***  Section 3.2                    ***
***************************************

***********************************
**** Donation levels by default codonation (pooled across different default donation levels)
***********************************

use defaults_donations.dta, clear

*drop top 0.2% of donors with highest donation levels
drop if q99_8==1

reg donated_amount C10 C15, cluster(session_id )
	test C10==C15
	

	
***********************************
**** Top coding (footnote 12)
***********************************	

use defaults_donations.dta, clear

preserve
collapse (mean) donation_sum , by(session_id )
su donation_sum  
*Mean overall donation among actual donors = 63.5666
*SD  = 208.3195
restore

*keep only donors whose (overall) donations do not lie more than three standard deviations above the overall mean of donations
gen don_3SD = 0
replace don_3SD = 1 if donate ==0 | donation_sum <=(63.5666+3*208.3195)

*compare donation levels and rates for alternative top-coding procedure
bys default_donation : su donated_amount if don_3SD

reg donated_amount   D10 D20 D50 if don_3SD ==1, cluster(sess)
test D50 = D10
test D50 = D20
test D10 = D20

reg donate D10 D20 D50 if don_3SD ==1, cluster(sess)
test D50 = D10
test D50 = D20
test D10 = D20
reg donate  D50 if don_3SD , cluster(sess)


	
***********************************
**** Dropping zeros
***********************************	

use defaults_donations.dta, clear

*drop top 0.2% of donors with highest donation levels
drop if q99_8==1

*sort in decreasing order of donation amounts within each treatment group;
gsort +default_donation -donated_amount
*number observations;
by default_donation: gen no_of_donor_within_treatment=_n
*determine total number obs in each group;
by default_donation: gen totno_of_obs_within_treatment=_N
*plot donation rate per treatment; maximum donation rate is .0339345
bys default_donation : su donate

*Analyze treatment effects on donation, keeping only .0339345 of participants per treatment
bys default_donation : gen max_donrate = round(.0339345*totno_of_obs_within_treatment)
bys default_donation : su donated_amount if no_of_donor<=max
reg donated_amount D10 D20 D50 if no_of_donor<=max , cluster(session_id )
test D10 = D20
test D10 = D50
test D20 = D50
	
	
	
********************************************
**** Differences in donation levels and rates for different donation "types" 
********************************************

use defaults_donations.dta, clear

*drop top 0.2% of donors with highest donation levels
drop if q99_8==1

*Treatment effects in donation levels by donation type
reg donated_amount D10 D20 D50 if receiver_type=="Project" , cluster(session_id )
test D10 = D20
test D10 = D50
test D20 = D50

reg donated_amount D10 D20 D50 if receiver_type=="Element" , cluster(session_id )
test D10 = D20
test D10 = D50
test D20 = D50
	
reg donated_amount D10 D20 D50 if receiver_type=="Event" , cluster(session_id )
test D10 = D20
test D10 = D50
test D20 = D50
	

*Treatment effects in donation rate by donation type: D50 vs. all other treatments
bys receiver_type: reg donate D50, cluster(session_id )



***************************************
***  Section 3.3                    ***
***************************************


********************************************
**** Differences in codonation levels for different donation defaults (footnote 16)
********************************************

use defaults_donations.dta, clear

*drop top 0.2% of donors with highest donation levels
drop if q99_8==1

* NOTE: T05 is reference category
global codon T010 T015 T105 T1010 T1015 T205 T2010 T2015 T505 T5010 T5015 

reg codonated_amount $codon, cluster(session_id )
*post estimation tests (holding codonation default constant)
test T105 = T205
test T105 = T505
test T205 = T505

test T010 = T1010
test T010 = T2010
test T010 = T5010
test T1010 = T2010
test T1010 = T5010
test T2010 = T5010

test T015 = T1015
test T015 = T2015
test T015 = T5015
test T1015 = T2015
test T1015 = T5015
test T2015 = T5015


********************************************
**** Extensive-margin reaction in codonation rate (footnote 17)
********************************************

use defaults_donations.dta, clear

*drop top 0.2% of donors with highest donation levels
drop if q99_8==1

*Summarize codonation rate under different codonation defaults
bys default_codonation: tab codonate if donate==1

*Test for differences in codonation rates
reg codonate C10 C15 D10 D20 D50 if donate==1, cluster(session_id)
test C10 = C15



log close
